package main

import (
	"fmt"

	"api/system/cmd"
	"api/system/crud"
	"api/system/helper"
	"api/system/orm"
	"github.com/fatih/color"
)

func execCrud() {
	color.Yellow("=============== 开始 ================")
	color.Green("开始生成CRUD文件")
	g := crud.New(cmd.Parser())
	var err error

	err = g.MakeController()
	if err != nil {
		fmt.Println(err.Error())
	}
	color.Green("生成接口控制器类完成.")

	if g.HasModel {
		err = g.MakeModel()
		if err != nil {
			fmt.Println(err.Error())
		}
		color.Green("生成模型器类完成.")
	}

	err = g.MakeValidate()
	if err != nil {
		fmt.Println(err.Error())
	}
	color.Green("生成接口验证器类完成.")

	err = g.MakeServiceFacade()
	if err != nil {
		fmt.Println(err.Error())
	}
	color.Green("生成接口服务门面类完成.")

	err = g.MakeServices()
	if err != nil {
		fmt.Println(err.Error())
	}
	color.Green("生成接口服务类完成.")
	color.Green("执行完毕！")
	color.Yellow("=============== 结束 ================")
}

func test() {
	res, err := orm.Table("custom_package", &orm.Conf{
		HostPort: 3306,
		Type:     "mysql",
		HostName: "127.0.0.1",
		DataBase: "laytp",
		UserName: "root",
		PassWord: "123456",
		Prefix:   "lt_",
	})
	if err != nil {
		helper.Dry(err.Error())
	}

	fmt.Println(res)
}

func main() {
	execCrud()
}
